package admin

import (
	"encoding/json"
	"github.com/gin-gonic/gin"
	"io/ioutil"
	"net/http"
	. "web_api_gin/controller"
	"web_api_gin/dto"
)

var GeographicApi = GeographicController{}

type GeographicController struct {
}

// 获取省市区列表
func (c *GeographicController) GetList(ctx *gin.Context) {
	resp, err := http.Get("https://wx.suofeiya.com.cn/new/api/region/getTreeList")
	if err != nil {
		ErrorWithMessage(ctx, http.StatusExpectationFailed, err.Error())
		return
	}

	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		ErrorWithMessage(ctx, http.StatusExpectationFailed, err.Error())
		return
	}
	var data *dto.ApiGeographic
	json.Unmarshal(body, &data)
	Success(ctx, data.Data)
}
